export interface IStack<T> {
  push(element: T): void;
  pop(): T | undefined;
  peek(): T | undefined;
  isEmpty(): boolean;
  size(): number;
}

export class ArrayStack<T> implements IStack<T> {
  //定义一个数组、链表，用于存储元素
  private data: T[] = [];

  //将一个元素弹出栈
  pop(): T | undefined {
    return this.data.pop();
  }

  //将一个元素压入栈内
  push(element: T): void {
    this.data.push(element);
  }

  //栈顶元素
  peek(): T | undefined {
    return this.data[this.data.length - 1];
  }

  //判断栈是否为空
  isEmpty(): boolean {
    return this.data.length === 0;
  }

  //返回栈的数据个数
  size(): number {
    return this.data.length;
  }
}
